Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add tests for TbdexQuoteNotifier #321

Merged
merged 4 commits into from
Oct 24, 2024

Conversation

mohitrajsinha
Copy link
Contributor

This PR introduces several tests for TbdexQuoteNotifier.
closes #293

});

group('TbdexQuoteNotifier Stress Tests', () {
test('High-frequency polling with exponential backoff', () async {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #312 (comment)

.thenAnswer((_) async => TestData.getExchange());
});

group('TbdexQuoteNotifier Stress Tests', () {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename this group to just TbdexQuoteNotifier

@ethan-tbd
Copy link
Contributor

take a look at the tests for AccountBalanceNotifier and TransactionNotifier to see how to better structure your test cases :)

@mohitrajsinha
Copy link
Contributor Author

Hey @ethan-tbd Check out the latest changes.


await mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId');

verify(() => mockTbdexQuoteNotifier.startPolling(any(), any())).called(1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the reason we are using any() here in startPolling()?

Comment on lines 37 to 45
test('should handle maximum retry attempts', () async {
when(() => mockTbdexQuoteNotifier.pollForQuote(any(), any()))
.thenThrow(Exception('Network error'));

await mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId');

verify(() => mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId'))
.called(1);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are throwing an Exception here but the test case only checks to see if startPolling() has been called

Comment on lines 26 to 35
test('should handle high-frequency polling with exponential backoff',
() async {
when(() => mockTbdexQuoteNotifier.pollForQuote(any(), any()))
.thenAnswer((_) async => TestData.getQuote());

await mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId');

verify(() => mockTbdexQuoteNotifier.startPolling('pfiId', 'exchangeId'))
.called(1);
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you want to test the exponential backoff, try verifying how many times getExchange() is called

Copy link
Contributor

@ethan-tbd ethan-tbd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice work!

@ethan-tbd ethan-tbd merged commit e5ce33b into TBD54566975:main Oct 24, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create tests for TbdexQuoteNotifier
3 participants